package com.agriculture.competition.service.impl;

import cn.hutool.core.convert.Convert;
import com.agriculture.common.core.utils.DateUtils;
import com.agriculture.common.core.utils.StringUtils;
import com.agriculture.competition.domain.JaReport;
import com.agriculture.competition.enums.Classify;
import com.agriculture.competition.mapper.JaClassifyMapper;
import com.agriculture.competition.mapper.JaReportMapper;
import com.agriculture.competition.service.IJaReportService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 研报信息Service业务层处理
 *
 * @author agriculture
 * @date 2024-11-12
 */
@Service
public class JaReportServiceImpl implements IJaReportService {

    @Autowired
    private JaReportMapper jaReportMapper;
    @Autowired
    private JaClassifyMapper jaClassifyMapper;

    /**
     * 查询研报信息
     *
     * @param reportId 研报信息主键
     * @return 研报信息
     */
    @Override
    public JaReport selectJaReportByReportId(Long reportId) {
        return jaReportMapper.selectJaReportByReportId(reportId);
    }

    /**
     * 查询研报信息列表
     *
     * @param jaReport 研报信息
     * @return 研报信息
     */
    @Override
    public List<JaReport> selectJaReportList(JaReport jaReport) {
        List<JaReport> jaReports = jaReportMapper.selectJaReportList(jaReport);
        for (JaReport report : jaReports) {
            if (StringUtils.isNotEmpty(report.getClassificationId())) {
                Long[] classificationIds = Convert.toLongArray(report.getClassificationId());
                List<String> classificationNames = jaClassifyMapper.selectJaClassifyNameByIds(Classify.REPORT_CLASSIFY, classificationIds);
                report.setClassificationList(classificationNames);
            }
            if (StringUtils.isNotEmpty(report.getSortId())) {
                Long[] sortIds = Convert.toLongArray(report.getSortId());
                List<String> sortNames = jaClassifyMapper.selectJaClassifyNameByIds(Classify.SORT_CLASSIFY, sortIds);
                report.setSortList(sortNames);
            }
        }
        return jaReports;
    }


    /**
     * 新增研报信息
     *
     * @param jaReport 研报信息
     * @return 结果
     */
    @Override
    public int insertJaReport(JaReport jaReport) {
        jaReport.setCreateTime(DateUtils.getNowDate());
        return jaReportMapper.insertJaReport(jaReport);
    }

    /**
     * 修改研报信息
     *
     * @param jaReport 研报信息
     * @return 结果
     */
    @Override
    public int updateJaReport(JaReport jaReport) {
        jaReport.setUpdateTime(DateUtils.getNowDate());
        return jaReportMapper.updateJaReport(jaReport);
    }

    /**
     * 批量删除研报信息
     *
     * @param reportIds 需要删除的研报信息主键
     * @return 结果
     */
    @Override
    public int deleteJaReportByReportIds(Long[] reportIds) {
        return jaReportMapper.deleteJaReportByReportIds(reportIds);
    }

    /**
     * 删除研报信息信息
     *
     * @param reportId 研报信息主键
     * @return 结果
     */
    @Override
    public int deleteJaReportByReportId(Long reportId) {
        return jaReportMapper.deleteJaReportByReportId(reportId);
    }
}
